package com.project.web.wechat.controller.app.webNative;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.common.core.utils.exception.Result;
import com.project.web.util.exception.WECHAT_RESP_CODE_ENUM;
import com.project.web.util.exception.WeChatCustomException;
import com.project.web.wechat.controller.common.BaseController;
import com.project.web.wechat.model.app.WxBizCropTagGroup;
import com.project.web.wechat.service.app.WxBizCropTagGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 企业标签组管理
 *
 * @Author: wyy
 * @Date: 4/8/21 4:49 PM
 */
@Api(tags = "【web】Crop Tag Group API")
@RestController("weChatServiceCropTagGroupController")
@RequestMapping("/weChat/auth/web/CropTagGroup")
public class WxBizCropTagGroupController extends BaseController {

    /**
     * 日志工具类
     */
    public static final Logger log = LoggerFactory.getLogger(WxBizCropTagGroupController.class);

    /**
     * 渠道标签业务接口
     */
    @Resource(name = "wxBizCropTagGroupServiceImpl")
    private WxBizCropTagGroupService wxBizCropTagGroupService;

    /**
     * 根据Id查询企业标签组
     *
     * @param id 主键ID
     * @return
     */
    @ApiOperation(value = "根据Id查询企业标签组")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "主键ID", dataType = "String")
    })
    @GetMapping(value = "/getById")
    public Result<WxBizCropTagGroup> getById(Long id) {
        if (null == id) {
            throw new WeChatCustomException(WECHAT_RESP_CODE_ENUM.MISS_PARAMETER);
        }
        WxBizCropTagGroup wxBizCropTagGroup = wxBizCropTagGroupService.getById(id);
        return getResult(wxBizCropTagGroup);
    }

    /**
     * 企业标签组列表【含分页】
     *
     * @param wxBizCropTagGroup 企业标签
     * @param pageNum           页码
     * @param pageSize          每页条数
     * @return
     */
    @ApiOperation(value = "企业标签组列表【含分页】")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页多少", dataType = "Integer")
    })
    @GetMapping(value = "/selectListOfPage")
    public Result<PageInfo<WxBizCropTagGroup>> selectListOfPage(WxBizCropTagGroup wxBizCropTagGroup, Integer pageNum, Integer pageSize) {
        if (pageNum == null || pageSize == null) {
            throw new WeChatCustomException(WECHAT_RESP_CODE_ENUM.MISS_PARAMETER);
        }
        PageHelper.startPage(pageNum, pageSize);
        List<WxBizCropTagGroup> wxBizCropTagGroups = wxBizCropTagGroupService.selectList(wxBizCropTagGroup);
        return getResult(new PageInfo(wxBizCropTagGroups));
    }

    /**
     * 企业标签组列表
     *
     * @param wxBizCropTagGroup 企业标签
     * @return
     */
    @ApiOperation(value = "企业标签组列表")
    @GetMapping(value = "/selectList")
    public Result<List<WxBizCropTagGroup>> selectList(WxBizCropTagGroup wxBizCropTagGroup) {

        List<WxBizCropTagGroup> wxBizCropTagGroups = wxBizCropTagGroupService.selectList(wxBizCropTagGroup);
        return getResult(wxBizCropTagGroups);
    }

    /**
     * 保存企业标签
     *
     * @param wxBizCropTagGroup 企业标签组
     * @return
     */
    @ApiOperation(value = "保存企业标签")
    @PostMapping(value = "/save")
    public Result<String> save(@RequestBody WxBizCropTagGroup wxBizCropTagGroup) {
        wxBizCropTagGroupService.save(wxBizCropTagGroup);
        return getResult("success");
    }

    /**
     * 更新企业标签组
     *
     * @param wxBizCropTagGroup 更新企业标签组
     * @return
     */
    @ApiOperation(value = "更新企业标签")
    @PostMapping(value = "/update")
    public Result<String> update(@RequestBody WxBizCropTagGroup wxBizCropTagGroup) {
        wxBizCropTagGroupService.update(wxBizCropTagGroup);
        return getResult("success");
    }

}
